package com.cy.网络编程.URL;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class Test {
    public static void main(String[] args) throws Exception {
        //1.创建url对象
        URL u = new URL("https://img1.baidu.com/it/u=3204709641,1185783480&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=816");
        //2.打开这个链接
        URLConnection uc = u.openConnection();
        //3.读取内容
        InputStream is = uc.getInputStream();
        FileOutputStream fos = new FileOutputStream(new File("src/money.jpg"));
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = is.read(bytes)) != -1) {
            fos.write(bytes, 0, len);
        }
        is.close();
        fos.flush();
        fos.close();
        System.out.println("下载完毕！");
    }
}
